﻿using System;
using System.Runtime.CompilerServices;

public interface Shape
{
    bool IsLegal();
    double GetArea();
}
public class Rectangle : Shape
{
    private double width;
    private double height;
public Rectangle(double width,double height)
    {
        this.width = width;
        this.height = height;
    }
public bool IsLegal()
    {
        if (width != 0 && height != 0) { return true; }
        else { return false; }
    }
public double GetArea()
    {
        return width * height;
    }
}

public class Square:Shape{
    private double width;
    public Square(double width)
    {
        this.width=width;
    }
    public bool IsLegal()
    {
        if (width != 0) { return true; }else { return false; }
    }
    public double GetArea()
    {
        return width * width;
    }
}
public class Triangle : Shape {
    private double a;
    private double b;
    private double c;
    public Triangle(double a,double b,double c)
    {
        this.a = a;this.b = b;this.c = c;
    }
    public bool IsLegal()
    {
        if (a + b < c && a + c < b && b + c < a)
        {
            return true;
        }
        else { return false; }
    }
    public double GetArea()
    {
        double p = (a + b + c) / 2;
        return Math.Sqrt((p * (p - a) * (p - b) * (p - c)));
            }
}
public static class ShapeFactory
{
    private static Random random = new Random();
    public static Shape CreateShape()
    {
        int shapeType = random.Next(0, 3);
        switch (shapeType) {
            case 0:
                return new Rectangle(random.Next(1, 10), random.Next(1, 10));
            case 1:
                return new Square(random.Next(1, 10));
            case 2:
                return new Triangle(random.Next(1, 10), random.Next(1, 10), random.Next(1, 10));
            default:
                throw new InvalidOperationException("Invalid shape type");
        }

    }
}
class Solution
{
    static void Main(string[]args)
    {
        List<Shape> shapes = new List<Shape>();

        for(int i = 0; i < 10; i++)
        {
            Shape shape = ShapeFactory.CreateShape();
            shapes.Add(shape);
        }
        double totalArea = 0;
        foreach (var shape in shapes)
        {
            if (shape.IsLegal())
            {
                totalArea += shape.GetArea();
            }
        }

        Console.WriteLine($"Total area of all shapes: {totalArea}");
}
}